﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace Stauffware.Common.Core
{
	/// <summary>
	/// Extension functions for collection classes.
	/// </summary>
	public static class Collection_Extensions
	{
		/// <summary>
		/// Returns the last item in the list, or null if the list is empty.
		/// </summary>
		public static object GetLast (this IList list)
		{
			if (list == null || list.Count == 0)
				return null;
			else return list[list.Count - 1];
		}

		/// <summary>
		/// Returns the last item in the list, or null if the list is empty.
		/// </summary>
		public static T GetLast<T> (this IList<T> list) where T : class
		{
			if (list == null || list.Count == 0)
				return null;
			else return list[list.Count - 1];
		}
	}
}
